import './index.scss'
import CONSTANT from '@/common/constants.js'
import http from '@/common/http.js'
import Scroller from 'vux/src/components/scroller/index.vue'
import LoadMore from 'vux/src/components/load-more/index.vue'
export default {
  name: 'findrank',
  components: { Scroller, LoadMore },
  data () {
    return {
      showList: [],
      dayList: [],
      mouthList: [],
      yearList: [],
      pageSize: 20,
      pageNoYear: 0,
      pageNoMouth: 0,
      pageNoDay: 0,
      pageNumberDay: -1,
      pageNumberMouth: -1,
      pageNumberYear: -1,
      isA: true,
      isB: false,
      isC: false,
      use_pullup: true,
      type: 'day',
      pullup_con: {
        content: ' ',
        pullUpHeight: 60,
        height: 40,
        autoRefresh: false,
        downContent: ' ',
        upContent: ' ',
        loadingContent: ' ',
        clsPrefix: 'xs-plugin-pullup-'
      },
      show_loading: false,
      tipText: '',
      bounce: false
    }
  },
  mounted () {
    if (this.$emit('ifOpenid')) {
      this.$emit('ifOpenid', this.$route.path)
    }
    this.show_loading = true
    this.onScrollBottom()
  },
  methods: {
    onScrollBottom () {
      if (this.isA == true) {
        this.pageNoDay ++
        this.type = 'day'
        this.show_loading = true
        http.post(CONSTANT.RECEIPT_RANK, {pageSize: this.pageSize, pageNo: this.pageNoDay, type: this.type}, (res) => {
          this.show_loading = false
          console.log(res)
          if (res.code == 200) {
            if (res.errmsg == '没有更多的排名') {
              if (this.pageNoDay > 1) {
                this.pageNoDay--
              }
              if (this.isA == true) {
                this.showList = this.dayList
              }
              this.tipText = '没有更多的排名'
              return
            }
            if (this.pageNoDay == 1) {
              this.dayList = res.list
            } else {
              this.dayList = this.dayList.concat(res.list)
            }
            if (this.dayList.length > 0) {
              this.pageNumberDay = this.dayList[0].pageNumber
            }
            if (this.isA == true) {
              this.showList = this.dayList
            }
            if (this.pageNoDay == 1) {
              this.$nextTick(() => {
                this.$refs.scroller.donePullup()
                this.$refs.scroller.reset({
                  top: 0
                })
              })
            } else {
              this.$nextTick(() => {
                this.$refs.scroller.donePullup()
                this.$refs.scroller.reset()
              })
            }
          } else {
            this.tipText = '服务器返回出错'
          }
        })
      } else if (this.isB == true) {
        this.show_loading = true
        this.type = 'month'
        this.pageNoMouth ++
        http.post(CONSTANT.RECEIPT_RANK, {pageSize: this.pageSize, pageNo: this.pageNoMouth, type: this.type}, (res) => {
          this.show_loading = false
          console.log(res)
          if (res.code == 200) {
            if (res.errmsg == '没有更多的排名') {
              if (this.pageNoMouth > 1) {
                this.pageNoMouth--
              }
              if (this.isB == true) {
                this.showList = this.mouthList
              }
              this.tipText = '没有更多的排名'
              return
            }
            if (this.pageNoMouth == 1) {
              this.mouthList = res.list
            } else {
              this.mouthList = this.mouthList.concat(res.list)
            }
            if (this.mouthList.length > 0) {
              this.pageNumberMouth = this.mouthList[0].pageNumber
            }
            if (this.isB == true) {
              this.showList = this.mouthList
            }
            if (this.pageNoMouth == 1) {
              this.$nextTick(() => {
                this.$refs.scroller.donePullup()
                this.$refs.scroller.reset({
                  top: 0
                })
              })
            } else {
              this.$nextTick(() => {
                this.$refs.scroller.donePullup()
                this.$refs.scroller.reset()
              })
            }
          } else {
            this.tipText = '服务器返回出错'
          }
        })
      } else if (this.isC == true) {
        this.pageNoYear ++
        this.type = 'year'
        this.show_loading = true
        http.post(CONSTANT.RECEIPT_RANK, {pageSize: this.pageSize, pageNo: this.pageNoYear, type: this.type}, (res) => {
          console.log(res)
          this.show_loading = false
          if (res.code == 200) {
            if (res.errmsg == '没有更多的排名') {
              if (this.pageNoYear > 1) {
                this.pageNoYear--
              }
              if (this.isC == true) {
                this.showList = this.yearList
              }
              this.tipText = '没有更多的排名'
              return
            }
            if (this.pageNoYear == 1) {
              this.yearList = res.list
            } else {
              this.yearList = this.yearList.concat(res.list)
            }

            if (this.yearList.length > 0) {
              this.pageNumberYear = this.yearList[0].pageNumber
            }
            if (this.isC == true) {
              this.showList = this.yearList
            }
            if (this.pageNoYear == 1) {
              this.$nextTick(() => {
                this.$refs.scroller.donePullup()
                this.$refs.scroller.reset({
                  top: 0
                })
              })
            } else {
              this.$nextTick(() => {
                this.$refs.scroller.donePullup()
                this.$refs.scroller.reset()
              })
            }
          } else {
            this.tipText = '服务器返回出错'
          }
        })
      }
      this.$nextTick(() => {
        this.$refs.scroller.donePullup()
        this.$refs.scroller.reset()
      })
    },
    isAShow () {
      this.isA = true
      this.isB = false
      this.isC = false
      this.tipText = ''
      if (this.pageNoDay == 0) {
        this.onScrollBottom()
      } else {
        this.showList = this.dayList
        this.$nextTick(() => {
          this.$refs.scroller.donePullup()
          this.$refs.scroller.reset({
            top: 0
          })
        })
      }
    },
    isBShow () {
      this.isA = false
      this.isB = true
      this.isC = false
      this.tipText = ''
      if (this.pageNoMouth == 0) {
        this.onScrollBottom()
      } else {
        this.showList = this.mouthList
        this.$nextTick(() => {
          this.$refs.scroller.donePullup()
          this.$refs.scroller.reset({
            top: 0
          })
        })
      }
    },
    isCShow () {
      this.isA = false
      this.isB = false
      this.isC = true
      this.tipText = ''
      if (this.pageNoYear == 0) {
        this.onScrollBottom()
      } else {
        this.showList = this.yearList
        this.$nextTick(() => {
          this.$refs.scroller.donePullup()
          this.$refs.scroller.reset({
            top: 0
          })
        })
      }
    },
    comeBack () {
      window.history.back()
    }
  }
}
